<?php

/**
 * SimplifyPHP Framework
 *
 * This file is part of SimplifyPHP Framework.
 *
 * SimplifyPHP Framework is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * SimplifyPHP Framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Rodrigo Rutkoski Rodrigues, <rutkoski@gmail.com>
 */

/**
 * Abstract Action Controller
 * 
 * @author Rodrigo Rutkoski Rodrigues <rutkoski@gmail.com>
 * @package Simplify_Kernel_Controller
 */
abstract class ActionController extends ActionControllerImpl
{

  /**
   * Default 404 action.
   * 
   * @return void
   */
  protected function action_404()
  {
    header('Status: 404 Not Found');
    $this->setTemplate('404');
  }

  /**
   * Default display action. Displays static actions.
   * 
   * @return void
   */
  protected function action_display()
  {
    $parts = func_get_args();
    
    $path = $this->config->get('{env}:home_dir') . '/' . implode('/', $parts);
    $path .= is_dir($path) ? '/index_action.php' : '_action.php';
   
    if (! file_exists($path))
      return $this->callAction('404');
    
    $this->setTemplate($path);
  }

  /**
   * Default index action.
   * 
   * @return void
   */
  protected function action_index()
  {
  }

  /**
   * Callback. Called after every action.
   * 
   * @param string $action action name
   * @param array $params action parameters
   * @param mixed $output action return value
   * @return void
   */
  protected function afterAction($action, $params, $output)
  {
  }

  /**
   * Callback. Called before every action.
   * 
   * @param string $action action name
   * @param array $params action parameters
   * @return void
   */
  protected function beforeAction($action, $params)
  {
  }

}

?>